<?php

namespace App\V3\V3_2_7\Models;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class QuotationNoModel extends Model
{


    use HasFactory;
    protected $table   = 'quotation_no';
    protected $dateFormat = 'U';//这个时间字段被为被格式化为UNIX 时间戳的形式存储
    //toArray 时间转换问题
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }
    protected $dates = [
        'tabel_time'
    ];


    public function nextTagList()
    {
        return self::hasMany(QuotationTagModel::class, 'quotation_id', 'id');
    }

    public function nextGoodsList()
    {
        return self::hasMany(QuotationGoodsModel::class, 'quotation_id', 'id');
    }
    static public function add($data){

        return QuotationNoModel::insertGetId($data);
    }
    static public function del($condition){

        return QuotationNoModel::where($condition)->delete();
    }
    static public function upd($condition,$data){

        return QuotationNoModel::where($condition)->update($data);
    }

    static public function getQuotationNoInfo($condition){

        return QuotationNoModel::where($condition)->first();
    }

    static public function getList($condition,$dispatch_id_arr,$pageSize,$pageNo){

        $query = QuotationNoModel::where($condition);

        if(!empty($dispatch_id_arr)){

            $query->whereIn('id',$dispatch_id_arr);
        }
        return  $query->orderBy('id','desc')
        ->paginate($pageSize,['*'], '',$pageNo)
        ->toArray();
    }
}
